package com.service;

import com.dao.DatasetDao;
import com.util.FileUtil;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;

public class DatasetOperator {

    /**
     * 获取数据集
     */
    public static String getDataSet() {
        //Use Redis
//        RedisConnection connection = new RedisConnection("Dataset_Download", "", "");
//        String last_result = "";
//        if((last_result = connection.search_query()) != null)
//            return last_result;

        //Use Mysql
        ArrayList<ArrayList<String>> search_result = DatasetDao.load_all_data();


        String last_result = "";
        if (search_result.size() > 0) {
            ArrayList<String> process_result = new ArrayList<>();
            //查找内容显示
            for (ArrayList<String> search_result_row : search_result) {
                String[] show_content = null;
                if (search_result_row.get(5) != null && !search_result_row.get(5).equals("")
                        && FileUtil.remote_file_exist(search_result_row.get(5)))
                    show_content = new String[]{search_result_row.get(1), search_result_row.get(3), search_result_row.get(6), search_result_row.get(5)};
                else
                    show_content = new String[]{search_result_row.get(1), search_result_row.get(3), search_result_row.get(6), "#"};

                process_result.add(StringUtils.join(show_content, "lxyniubi"));
            }
            last_result = StringUtils.join(process_result.toArray(), "wlcniubi");
        }
        last_result = last_result.replaceAll("\"|'|\r\n|\r|\n|\\s*", "");

//        connection.set_search_query(last_result);
        return last_result;
    }


}
